package sxe.core.cs511.team2_2;
import java.util.Vector;
/**
 * OVERVIEW: A sequence of blobs of the same object from different frames.
 * 
 * The abstraction function is AF(c)={c.blobs[0], c.blobs[1], ... c.blobs[c.blobs.size-1]}
 * 
 * The rep invariant is:
 *   blobs.size > 0 && (blobs[i].time < blobs[j].time) for all i<j
 *   
 * @author skelly
 *
 */
public class Track {
	/**
	 * EFFECTS: initializes sequence to one element, b
	 */
	public Track(Blob b){
		blobs.add(b);
	}
	/**
	 * REQUIRES: b.timeStamp > timeStamp of all other blobs in sequence
	 * MODIFIES: this
	 * EFFECTS: sets b to be most recent blob in sequence
	 */
	public void add(Blob b){blobs.add(b);}
	/**
	 * EFFECTS: returns most recent blob of seqence
	 */
	public Blob mostRecent(){
		return blobs.lastElement();}
	/**
	 * EFFECTS: returns least recent blob of sequence
	 */
	public Blob leastRecent(){return blobs.get(0);}
	/**
	 * EFFECTS: returns positional difference between last two blobs
	 * 			if there is only one blob, returns (0,0) 
	 */
	public double[] lastVelocity(){
		double v[] = new double[2];
		if(blobs.size()==1)
		{
			v[0]=0;
			v[1]=0;
		}
		else
		{
			v[0]=blobs.get(blobs.size()-1).getX()-blobs.get(blobs.size()-2).getX();
			v[1]=blobs.get(blobs.size()-1).getY()-blobs.get(blobs.size()-2).getY();
		}
		return v;
	}
	/**
	 * EFFECTS: returns positional difference between first two blobs
	 * 			if there is only one blob, returns (0,0) 
	 */
	public double[] firstVelocity(){
		double v[] = new double[2];
		if(blobs.size()==1)
		{
			v[0]=0;
			v[1]=0;
		}
		else
		{
			v[0]=blobs.get(1).getX()-blobs.get(0).getX();
			v[1]=blobs.get(1).getY()-blobs.get(0).getY();
		}
		return v;
	}
	/**
	 * EFFECTS: returns number of blobs in sequence
	 */
	public long length(){return blobs.size();}
	private Vector<Blob> blobs=new Vector<Blob>();
}
